package com.zfl.thread.day04;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;

public class SemaphoreDemo04 {
    public static void main(String[] args) {
        ExecutorService pool = Executors.newFixedThreadPool(50);
        Semaphore semaphore = new Semaphore(10);
        for (int i = 0; i < 50; i++) {
            pool.execute(()->{
                try {
                    semaphore.acquire();
                    System.out.println(Thread.currentThread().getName()+"进来了-----");
                    Thread.sleep(2000);
                    System.out.println(Thread.currentThread().getName()+"出来了");
                    semaphore.release();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            });
        }
        pool.shutdown();
    }
}
